package vista;

import dao.DAOCliente;
import dao.DAOInmueble;
import dao.DAOReservaInmueble;
import dao.DAOVendedor;
import entidades.Cliente;
import entidades.Inmueble;
import entidades.ReservaInmueble;
import entidades.ReservaInmuebleId;
import entidades.Vendedor;
import inmobiliariafrsf.GenerarReserva;
import java.awt.Color;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 * Interfaz para realizar la reserva de un inmueble
 */
public class VReservaInmueble extends javax.swing.JDialog {

    /**
     * Inmueble sobre el que se va a realizar la reserva
     */
    Inmueble reservaInmueble;
    /**
     * Cliente que va a realizar la reserva
     */
    Cliente reservaCliente;
    /**
     * Numero de documento del cliene
     */
    String numDoc_cliente;
    
    /**
     * Constructor de la interfaz
     * 
     * @param parent
     * @param modal
     * @param inmueble 
     */
    public VReservaInmueble(java.awt.Frame parent, boolean modal, Inmueble inmueble) {
        
        super(parent, modal);
        this.reservaInmueble = inmueble;
        initComponents();
        
        if (this.reservaInmueble != null){
            this.lCodigoInmueble.setText(this.reservaInmueble.getCodigo());
            this.lTipoInmueble.setText(DAOCliente.getInmuebleTipoEnum(this.reservaInmueble.getTipo()).toString());
            this.lFrenteInmueble.setText(Double.toString(this.reservaInmueble.getFrente()) + "mts");
            this.lFondoInmueble.setText(Double.toString(this.reservaInmueble.getFondo()) + "mts");
            this.lSuperficieInmueble.setText(Double.toString(this.reservaInmueble.getSuperficie()) + "m2");
            this.lAntiguedadInmueble.setText(Integer.toString(this.reservaInmueble.getAntiguedad()) + "años");
            this.lDormitoriosInmueble.setText(this.reservaInmueble.getDormitorios().toString());
            this.lBanosInmueble.setText(Byte.toString(this.reservaInmueble.getBanos()));
            
            Vector<String> otrasCaracteristicas = new Vector<String>();
            if (this.reservaInmueble.isGarage())
                otrasCaracteristicas.add("+Garage ");
            if (this.reservaInmueble.isAguaCorriente())
                otrasCaracteristicas.add("+Agua Corriente ");
            if (this.reservaInmueble.isAguaCaliente())
                otrasCaracteristicas.add("+Agua Caliente ");
            if (this.reservaInmueble.isTelefono())
                otrasCaracteristicas.add("+Telefono ");
            if (this.reservaInmueble.isPatio())
                otrasCaracteristicas.add("+Patio ");
            if (this.reservaInmueble.isCloacas())
                otrasCaracteristicas.add("+Cloacas ");
            if (this.reservaInmueble.isLavadero())
                otrasCaracteristicas.add("+Lavadero ");
            if (this.reservaInmueble.isPiscina())
                otrasCaracteristicas.add("+Piscina ");
            if (this.reservaInmueble.isGas())
                otrasCaracteristicas.add("+Gas ");
            if (this.reservaInmueble.isPavimento())
                otrasCaracteristicas.add("+Pavimento ");
            
            int cant = otrasCaracteristicas.size();
            Iterator it = otrasCaracteristicas.iterator();

            String otras1 = "";
            String otras2 = "";
            
            if (0 == cant) 
                otras1 = "-";
            else {
                if (cant <= 5) {
                while (it.hasNext()) {
                    otras1 += it.next().toString();
                    }
                }
                else{
                    for (int i=0; i<5; i++){
                        otras1 += it.next().toString();
                    }
                    while (it.hasNext()) {
                        otras2 += it.next().toString();
                    }
                }
            }
            
            this.lOtrasInmueble1.setText(otras1);
            this.lOtrasInmueble2.setText(otras2);
            
            this.lProvinciaInmueble.setText(this.reservaInmueble.getLocalidad().getProvincia().getNombre());
            this.lLocalidadInmueble.setText(this.reservaInmueble.getLocalidad().getNombre());
            
            //Construccion del String de direccion del inmueble
            String direccion = this.reservaInmueble.getCalle() + " " + Short.toString(this.reservaInmueble.getNumero());
            if (this.reservaInmueble.getPiso() == null)
                direccion += " " + Byte.toString(this.reservaInmueble.getPiso()) + " " + this.reservaInmueble.getDepartamento();
            
            this.lDomicilioInmueble.setText(direccion);
            
            this.lBarrioInmueble.setText(this.reservaInmueble.getBarrio());
            this.lOrientacionInmueble.setText(this.reservaInmueble.getOrientacion());
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pInmueble = new javax.swing.JPanel();
        lProvincia = new javax.swing.JLabel();
        lLocalidad = new javax.swing.JLabel();
        lDomicilio = new javax.swing.JLabel();
        lBarrio = new javax.swing.JLabel();
        lOrientacion = new javax.swing.JLabel();
        lCodigo = new javax.swing.JLabel();
        lCodigoInmueble = new javax.swing.JLabel();
        lTipo = new javax.swing.JLabel();
        lTipoInmueble = new javax.swing.JLabel();
        lFrente = new javax.swing.JLabel();
        lFondo = new javax.swing.JLabel();
        lSuperficie = new javax.swing.JLabel();
        lFrenteInmueble = new javax.swing.JLabel();
        lFondoInmueble = new javax.swing.JLabel();
        lSuperficieInmueble = new javax.swing.JLabel();
        lAntiguedad = new javax.swing.JLabel();
        lDormitorios = new javax.swing.JLabel();
        lBanos = new javax.swing.JLabel();
        lOtras = new javax.swing.JLabel();
        lProvinciaInmueble = new javax.swing.JLabel();
        lLocalidadInmueble = new javax.swing.JLabel();
        lDomicilioInmueble = new javax.swing.JLabel();
        lBarrioInmueble = new javax.swing.JLabel();
        lOrientacionInmueble = new javax.swing.JLabel();
        lAntiguedadInmueble = new javax.swing.JLabel();
        lDormitoriosInmueble = new javax.swing.JLabel();
        lBanosInmueble = new javax.swing.JLabel();
        lOtrasInmueble1 = new javax.swing.JLabel();
        lOtrasInmueble2 = new javax.swing.JLabel();
        pCliente = new javax.swing.JPanel();
        lNombreCliente = new javax.swing.JLabel();
        btnBuscar = new javax.swing.JButton();
        tNombreCliente = new javax.swing.JTextField();
        bGuardar = new javax.swing.JButton();
        bCancelar = new javax.swing.JButton();
        caracteristicaReserva = new javax.swing.JPanel();
        importeReserva = new javax.swing.JLabel();
        tiempoVigencia = new javax.swing.JLabel();
        txtImporte = new javax.swing.JTextField();
        txtTiempo = new javax.swing.JTextField();
        lbImporte = new javax.swing.JLabel();
        lbTiempo = new javax.swing.JLabel();
        lVendedor = new javax.swing.JLabel();
        cbVendedor = new javax.swing.JComboBox(DAOVendedor.getAllNombreApellido());
        ;

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("vReservaInmueble"); // NOI18N

        pInmueble.setBorder(javax.swing.BorderFactory.createTitledBorder("Información Inmueble"));

        lProvincia.setText("Provincia:");

        lLocalidad.setText("Localidad:");

        lDomicilio.setText("Domicilio:");

        lBarrio.setText("Barrio:");

        lOrientacion.setText("Orientación:");

        lCodigo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lCodigo.setText("Código de Inmueble:");

        lCodigoInmueble.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lCodigoInmueble.setText("############");

        lTipo.setText("Tipo de Inmueble:");

        lTipoInmueble.setText("Departamento");

        lFrente.setText("Metros de Frente:");

        lFondo.setText("Metros de Fondo:");

        lSuperficie.setText("Superficie:");

        lFrenteInmueble.setText("####### mts");

        lFondoInmueble.setText("####### mts");

        lSuperficieInmueble.setText("####### mts");

        lAntiguedad.setText("Antigüedad:");

        lDormitorios.setText("Dormitorios:");

        lBanos.setText("Baños:");

        lOtras.setText("Otras características:");

        lProvinciaInmueble.setText("                                  .");

        lLocalidadInmueble.setText("                                  .");

        lDomicilioInmueble.setText("                                  .");

        lBarrioInmueble.setText("                                  .");

        lOrientacionInmueble.setText("                                  .");

        lAntiguedadInmueble.setText("####### mts");

        lDormitoriosInmueble.setText("####### mts");

        lBanosInmueble.setText("####### mts");

        lOtrasInmueble1.setText("CARAAAAAAAAAAAAACTERISTICAS");

        lOtrasInmueble2.setText("CARAAAAAAAAAAAAACTERISTICAS");

        javax.swing.GroupLayout pInmuebleLayout = new javax.swing.GroupLayout(pInmueble);
        pInmueble.setLayout(pInmuebleLayout);
        pInmuebleLayout.setHorizontalGroup(
            pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pInmuebleLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pInmuebleLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pInmuebleLayout.createSequentialGroup()
                                .addComponent(lCodigo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lCodigoInmueble))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pInmuebleLayout.createSequentialGroup()
                                .addComponent(lTipo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lTipoInmueble)
                                .addGap(36, 36, 36)))
                        .addGap(143, 143, 143))
                    .addGroup(pInmuebleLayout.createSequentialGroup()
                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pInmuebleLayout.createSequentialGroup()
                                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lBarrio)
                                    .addComponent(lProvincia)
                                    .addComponent(lDomicilio))
                                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pInmuebleLayout.createSequentialGroup()
                                        .addGap(46, 46, 46)
                                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lFrenteInmueble)
                                            .addComponent(lAntiguedadInmueble))
                                        .addGap(18, 18, 18)
                                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(lDormitorios)
                                            .addComponent(lFondo))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lFondoInmueble)
                                            .addComponent(lDormitoriosInmueble))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(lBanos)
                                            .addComponent(lSuperficie))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lSuperficieInmueble)
                                            .addComponent(lBanosInmueble)))
                                    .addGroup(pInmuebleLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lDomicilioInmueble, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(pInmuebleLayout.createSequentialGroup()
                                                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(lProvinciaInmueble)
                                                    .addComponent(lBarrioInmueble))
                                                .addGap(87, 87, 87)
                                                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                    .addGroup(pInmuebleLayout.createSequentialGroup()
                                                        .addGap(1, 1, 1)
                                                        .addComponent(lOrientacion)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(lOrientacionInmueble))
                                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pInmuebleLayout.createSequentialGroup()
                                                        .addComponent(lLocalidad)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(lLocalidadInmueble, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))))))))
                            .addGroup(pInmuebleLayout.createSequentialGroup()
                                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lFrente)
                                    .addComponent(lAntiguedad))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(pInmuebleLayout.createSequentialGroup()
                                .addComponent(lOtras)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lOtrasInmueble2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lOtrasInmueble1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addContainerGap())))
        );
        pInmuebleLayout.setVerticalGroup(
            pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pInmuebleLayout.createSequentialGroup()
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lCodigo)
                    .addComponent(lCodigoInmueble))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lTipo)
                    .addComponent(lTipoInmueble))
                .addGap(18, 18, 18)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lFrente)
                    .addComponent(lFondo)
                    .addComponent(lSuperficie)
                    .addComponent(lFrenteInmueble)
                    .addComponent(lFondoInmueble)
                    .addComponent(lSuperficieInmueble))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lAntiguedad)
                    .addComponent(lDormitorios)
                    .addComponent(lBanos)
                    .addComponent(lAntiguedadInmueble)
                    .addComponent(lDormitoriosInmueble)
                    .addComponent(lBanosInmueble))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lOtras)
                    .addGroup(pInmuebleLayout.createSequentialGroup()
                        .addComponent(lOtrasInmueble1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lOtrasInmueble2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lProvincia)
                    .addComponent(lProvinciaInmueble)
                    .addComponent(lLocalidad)
                    .addComponent(lLocalidadInmueble))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lDomicilio)
                    .addComponent(lDomicilioInmueble))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pInmuebleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lBarrio)
                    .addComponent(lOrientacion)
                    .addComponent(lOrientacionInmueble)
                    .addComponent(lBarrioInmueble))
                .addGap(24, 24, 24))
        );

        pCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Cliente comprador"));

        lNombreCliente.setText("Nombre Completo:");

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/search_button_green_16.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        tNombreCliente.setEditable(false);
        tNombreCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tNombreClienteMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout pClienteLayout = new javax.swing.GroupLayout(pCliente);
        pCliente.setLayout(pClienteLayout);
        pClienteLayout.setHorizontalGroup(
            pClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lNombreCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(tNombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnBuscar)
                .addGap(278, 278, 278))
        );
        pClienteLayout.setVerticalGroup(
            pClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lNombreCliente)
                    .addComponent(btnBuscar)
                    .addComponent(tNombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/disk.png"))); // NOI18N
        bGuardar.setText("Aceptar");
        bGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarActionPerformed(evt);
            }
        });

        bCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/close_16.png"))); // NOI18N
        bCancelar.setText("Cancelar");
        bCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelarActionPerformed(evt);
            }
        });

        caracteristicaReserva.setBorder(javax.swing.BorderFactory.createTitledBorder("Caracteristicas reserva"));

        importeReserva.setText("Importe de Reserva:");

        tiempoVigencia.setText("Tiempo de Vigencia:");

        txtImporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtImporteActionPerformed(evt);
            }
        });

        lbImporte.setText("(en pesos)");

        lbTiempo.setText("(en dias)");

        lVendedor.setText("Vendedor:");

        cbVendedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbVendedorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout caracteristicaReservaLayout = new javax.swing.GroupLayout(caracteristicaReserva);
        caracteristicaReserva.setLayout(caracteristicaReservaLayout);
        caracteristicaReservaLayout.setHorizontalGroup(
            caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(caracteristicaReservaLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(caracteristicaReservaLayout.createSequentialGroup()
                        .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tiempoVigencia)
                            .addComponent(lVendedor))
                        .addGap(23, 23, 23)
                        .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtTiempo)
                            .addComponent(cbVendedor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(caracteristicaReservaLayout.createSequentialGroup()
                        .addComponent(importeReserva)
                        .addGap(18, 18, 18)
                        .addComponent(txtImporte)))
                .addGap(18, 18, 18)
                .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbImporte)
                    .addComponent(lbTiempo))
                .addGap(81, 81, 81))
        );
        caracteristicaReservaLayout.setVerticalGroup(
            caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(caracteristicaReservaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(importeReserva)
                    .addComponent(txtImporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbImporte))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tiempoVigencia)
                        .addComponent(txtTiempo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lbTiempo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(caracteristicaReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lVendedor)
                    .addComponent(cbVendedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(bGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(pInmueble, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(pCliente, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 554, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(caracteristicaReserva, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pInmueble, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(caracteristicaReserva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bGuardar)
                    .addComponent(bCancelar))
                .addGap(22, 22, 22))
        );

        setSize(new java.awt.Dimension(590, 624));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void tNombreClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tNombreClienteMouseClicked
    }//GEN-LAST:event_tNombreClienteMouseClicked

    private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
       Integer importe = new Integer(0);
       Integer tiempo = new Integer(0); 
       
       if(!this.txtImporte.getText().isEmpty()) {
           try{
              importe = Integer.parseInt(txtImporte.getText()); 
              txtImporte.setForeground(Color.black);
           }
           catch(NumberFormatException e) {
                JOptionPane.showMessageDialog(this, "El Importe debe ser un número", "Error! Valor del Importe", JOptionPane.ERROR_MESSAGE);
                txtImporte.setForeground(Color.red);
                return;
            }
       }
       else{
           JOptionPane.showMessageDialog(this, "El Importe debe ser completado", "Error! Valor del Importe", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(!this.txtTiempo.getText().isEmpty()) {
           try{
              tiempo = Integer.parseInt(txtTiempo.getText()); 
              txtTiempo.setForeground(Color.black);
           }
           catch(NumberFormatException e) {
                JOptionPane.showMessageDialog(this, "El Tiempo de Reserva debe ser un número entero", "Error! Tiempo de Reserva", JOptionPane.ERROR_MESSAGE);
                txtTiempo.setForeground(Color.red);
                return;
            }
       }
       else{
           JOptionPane.showMessageDialog(this, "El Tiempo de Reserva debe ser completado", "Error! Tiempo de Reserva", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(cbVendedor.getSelectedIndex() < 1){
           JOptionPane.showMessageDialog(this, "Debe seleccionar un vendedor", "Error! Vendedor", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(tNombreCliente.getText().isEmpty()){
           JOptionPane.showMessageDialog(this, "Debe seleccionar un cliente", "Error! Cliente", JOptionPane.ERROR_MESSAGE);
           return;
       }
       
       ReservaInmueble reserva = new ReservaInmueble();
       Vendedor vendedor = DAOVendedor.getByNombre(cbVendedor.getSelectedItem().toString());
       
       if(txtImporte == null || txtTiempo == null){
           JOptionPane.showMessageDialog(this, "Todos los campos deben ser completados", "Error!", JOptionPane.ERROR_MESSAGE);
       }
       else{
           reserva.setId(new ReservaInmuebleId(reservaInmueble.getIdInmueble(), new Date()));
           reserva.setInmueble(reservaInmueble);
           reserva.setVendedor(vendedor);
           reserva.setCliente(reservaCliente);
           reserva.setImporte(importe);
           reserva.setTiempoVigencia(tiempo);
       
            //Generar reporte
           new GenerarReserva(reserva, lOtrasInmueble1.getText(), lOtrasInmueble2.getText());
           
           //Reserva logica
           if(DAOReservaInmueble.insertOrUpdate(reserva)) {
               reservaInmueble.getReservaInmuebles().add(reserva);
           }
           else {
               JOptionPane.showMessageDialog(this, "No se pudo guardar la reserva", "Error!", JOptionPane.ERROR_MESSAGE);
           }
           
           this.dispose();
       }

    }//GEN-LAST:event_bGuardarActionPerformed

    private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_bCancelarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        VBuscarPersona vBc = new VBuscarPersona(this, "Cliente");
        vBc.setVisible(true);
    }//GEN-LAST:event_btnBuscarActionPerformed

private void txtImporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtImporteActionPerformed

}//GEN-LAST:event_txtImporteActionPerformed

    private void cbVendedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbVendedorActionPerformed
        
    }//GEN-LAST:event_cbVendedorActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

    }
    
    public void setNumDocCliente(String numDoc_cliente) 
    {
        this.numDoc_cliente = numDoc_cliente;
        if(numDoc_cliente != null) {
            reservaCliente = DAOCliente.getByNumDoc(numDoc_cliente);
            
            if(reservaCliente != null) {
                tNombreCliente.setText(reservaCliente.getApellido()+", "+reservaCliente.getNombre());
            }
            else {
                this.tNombreCliente.setText("Cliente no encontrado");
                JOptionPane.showMessageDialog(this, "El cliente no pudo Encontrarse", "Algo salió mal", JOptionPane.ERROR_MESSAGE);
            }
        }
        else {
            this.tNombreCliente.setText("Cliente no seleccionado");
            JOptionPane.showMessageDialog(this, "El cliente no pudo Encontrarse", "Algo salió mal", JOptionPane.ERROR_MESSAGE);
        }
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bGuardar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JPanel caracteristicaReserva;
    private javax.swing.JComboBox cbVendedor;
    private javax.swing.JLabel importeReserva;
    private javax.swing.JLabel lAntiguedad;
    private javax.swing.JLabel lAntiguedadInmueble;
    private javax.swing.JLabel lBanos;
    private javax.swing.JLabel lBanosInmueble;
    private javax.swing.JLabel lBarrio;
    private javax.swing.JLabel lBarrioInmueble;
    private javax.swing.JLabel lCodigo;
    private javax.swing.JLabel lCodigoInmueble;
    private javax.swing.JLabel lDomicilio;
    private javax.swing.JLabel lDomicilioInmueble;
    private javax.swing.JLabel lDormitorios;
    private javax.swing.JLabel lDormitoriosInmueble;
    private javax.swing.JLabel lFondo;
    private javax.swing.JLabel lFondoInmueble;
    private javax.swing.JLabel lFrente;
    private javax.swing.JLabel lFrenteInmueble;
    private javax.swing.JLabel lLocalidad;
    private javax.swing.JLabel lLocalidadInmueble;
    private javax.swing.JLabel lNombreCliente;
    private javax.swing.JLabel lOrientacion;
    private javax.swing.JLabel lOrientacionInmueble;
    private javax.swing.JLabel lOtras;
    private javax.swing.JLabel lOtrasInmueble1;
    private javax.swing.JLabel lOtrasInmueble2;
    private javax.swing.JLabel lProvincia;
    private javax.swing.JLabel lProvinciaInmueble;
    private javax.swing.JLabel lSuperficie;
    private javax.swing.JLabel lSuperficieInmueble;
    private javax.swing.JLabel lTipo;
    private javax.swing.JLabel lTipoInmueble;
    private javax.swing.JLabel lVendedor;
    private javax.swing.JLabel lbImporte;
    private javax.swing.JLabel lbTiempo;
    private javax.swing.JPanel pCliente;
    private javax.swing.JPanel pInmueble;
    private javax.swing.JTextField tNombreCliente;
    private javax.swing.JLabel tiempoVigencia;
    private javax.swing.JTextField txtImporte;
    private javax.swing.JTextField txtTiempo;
    // End of variables declaration//GEN-END:variables
}
